package com.ht.medicaltreatment.viewmodel

import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.ToastUtils
import com.ht.medicaltreatment.bean.PDPage
import com.xgst.lib.http.ApiResult
import kotlinx.coroutines.launch

class InventoryListViewModel:BaseViewModel() {

    //sign: 检索条件(0:检索所有数据,1:检索核验中/未核验的数据)
    fun request(currentPage:String,sign:String,onSuccess:(MutableList<PDPage>?)->Unit){
        viewModelScope.launch {
            val bean =  mApi.pdList(currentPage,"20",sign)
            when(bean){
                is ApiResult.Success -> onSuccess(bean.data.data?.pageList)
                is ApiResult.Error ->{
                    dismissProgress()
                    ToastUtils.showShort(bean.errorMessage)
                }
            }
        }
    }

    fun delete(pdId:String,onSuccess:()->Unit){
        viewModelScope.launch {
            val bean =  mApi.deletePD(pdId)
            when(bean){
                is ApiResult.Success -> onSuccess()
                is ApiResult.Error -> dismissProgress(bean.errorMessage)
            }
        }
    }
}